package com.javabasic.concurrency;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/4/23 19:40
 * @Version 1.0
 * @TODO 如何优雅的关闭线程
 **/
public class InterruptTest {

    public static void main(String[] args)  {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(500);
                for (int i = 0; i < 100; i++) {
                    System.out.println("i am " + i);
                    if (i == 50) {

                    }
                }
            } catch (InterruptedException e) {
                System.out.println("Error :" + e.getMessage());
            }
        });
        thread.start();
//        try {
//            Thread.sleep(550);
//        } catch (InterruptedException e) {
//            System.out.println(e.getMessage());
//        }
        thread.interrupt();


//        System.out.println(Thread.interrupted());

        if (thread.isInterrupted()) {
            System.out.println("true " + thread.isInterrupted());
            System.out.println(Thread.currentThread().getName());
            System.out.println(Thread.interrupted());
            System.out.println("true " + thread.isInterrupted());
        } else {
            System.out.println("false");
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
